package com.yty.newconsult.service.impl;

import com.yty.newconsult.entity.QueryMessage;
import com.yty.newconsult.dao.QueryHistoryDao;
import com.yty.newconsult.service.QueryHistoryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (QueryHistory)表服务实现类
 *
 * @author makejava
 * @since 2025-04-08 19:30:28
 */
@Service("queryHistoryService")
public class QueryHistoryServiceImpl implements QueryHistoryService {
    @Resource
    private QueryHistoryDao queryHistoryDao;




    @Override
    public List<QueryMessage> queryByUserId(String userId) {
        return queryHistoryDao.queryByUserId(userId);
    }

    /**
     * 分页查询
     *
     * @param queryMessage 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<QueryMessage> queryByPage(QueryMessage queryMessage, PageRequest pageRequest) {
        long total = this.queryHistoryDao.count(queryMessage);
        return new PageImpl<>(this.queryHistoryDao.queryAllByLimit(queryMessage, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param queryMessage 实例对象
     * @return 实例对象
     */
    @Override
    public QueryMessage insert(QueryMessage queryMessage) {
        this.queryHistoryDao.insert(queryMessage);
        return queryMessage;
    }

    /**
     * 修改数据
     *
     * @param queryHistory 实例对象
     * @return 实例对象
     */


    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.queryHistoryDao.deleteById(id) > 0;
    }
}
